package com.m3958.firstgwt.client.datasource;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.m3958.firstgwt.client.constants.AssetFieldConstants;
import com.m3958.firstgwt.shared.type.AssetField;
import com.m3958.firstgwt.shared.type.CommonField;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

@Singleton
public class AssetDataSource extends BaseDataSource{

    public static String className = "com.m3958.firstgwt.server.model.Asset";
    
    @Inject
    public AssetDataSource(DsErrorHandler deh,AssetFieldConstants constants) {
    	setID("assetDS");
    	
    	DataSourceTextField thumbnailField = new DataSourceTextField(AssetField.THUMBNAIL.getValue(),constants.thumbnail());
        DataSourceTextField descriptionField = new DataSourceTextField(CommonField.DESCRIPTION.getValue(),constants.description());
        DataSourceTextField filePathField = new DataSourceTextField(AssetField.FILE_PATH.getValue(),constants.filePath());
        DataSourceTextField fileIdField = new DataSourceTextField(AssetField.FILE_ID.getValue(),constants.fileId());
        DataSourceIntegerField fileSizeField = new DataSourceIntegerField(AssetField.FILE_SIZE.getValue(),constants.fileSize());
        DataSourceTextField mimeTypeField = new DataSourceTextField(AssetField.MIME_TYPE.getValue(),constants.mimeType());
        DataSourceTextField originNameField = new DataSourceTextField(AssetField.ORIGIN_NAME.getValue(),constants.originName());
        DataSourceBooleanField isImgField = new DataSourceBooleanField(AssetField.IMG.getValue(),constants.img());
        addHandleErrorHandler(deh);
        
        setFields(getIdField(),getVersionField(),getSiteIdField(constants),thumbnailField,filePathField,fileIdField,fileSizeField,mimeTypeField,originNameField,descriptionField,getCreatedAtField(false,constants),getPublishedAtField(false),getProtectLevelField(),isImgField);
        setClientOnly(false);
       
    }

	@Override
	protected String getModelClassName() {
		return className;
	}
    
}
